package com.xykj.sdkdemo

import android.content.Intent
import android.net.Uri
import android.os.Build
import android.os.Environment
import cn.chw.SDK.Entity.FileMsg
import com.blankj.utilcode.util.ImageUtils
import com.blankj.utilcode.util.LogUtils
import java.io.File


/**
 * 刷新相册
 */
fun refreshAlbum(filePath: String?) {
    LogUtils.e(ImageUtils.getRotateDegree(filePath))
    val uri = Uri.fromFile(File(filePath))
    val mediaScanIntent = Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, uri)
    APP.getInstance().sendBroadcast(mediaScanIntent)
}

fun getLogPath(): String? {
    val logFilePath = getSDCardPath() + "/SDKDEMO" + "/log"
    val logFile = File(logFilePath)
    if (!logFile.exists()) logFile.mkdirs()
    return "$logFilePath/VEnginelogs.txt"
}


/**
 * 获取本地文件路径
 *
 * @param fileType
 * @return
 */
fun getLocalFilePath(fileType: Int): String? {
    var path = getAppPath() + "/file/"
    when (fileType) {
        FileMsg.FileTypePic -> path += "images/"
        FileMsg.FileTypeVoice -> path += "audios/"
        FileMsg.FileTypeVideo -> path += "videos/"
        FileMsg.FileTypeOther -> path += "files/"
        FileMsg.FileTypeGisinfo -> path += "location/"
    }
    val localPath = File(path)
    if (!localPath.exists()) localPath.mkdirs()
    return path
}

/**
 * 获取应用文件目录
 *
 * @return
 */
fun getAppPath(): String {
    return getSDCardPath() + "/SDKDEMO"
}

fun getSDCardPath(): String {
    return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
        "/sdcard"
    } else {
        Environment.getExternalStorageDirectory().absolutePath
    }
}
